<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class LoginController extends Controller
{
    //登录入口
    public function index()
    {
        return view('login/index');
    }

    //登录入口
    public function login(Request $request)
    {
        //验证数据
        $this->validate($request, [
            'email'       => 'required|email',
            'password'    => 'required|min:6',
            'is_remember' => 'integer',
        ]);

        $userInfo = \request(['email', 'password']);
        $isRemember = boolval(\request('is_remember'));
        if (Auth::attempt($userInfo, $isRemember)) {
            return redirect('/drawer');
        }

        return back()->withErrors('邮箱和密码不匹配');
    }

    /**
     * 退出
     * @date 2017/7/22
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
     */
    public function logout()
    {
        Auth::logout();

        return redirect('/login');
    }
}
